//
//  SystemMessageController.m
//  OnionHome
//
//  Created by fengjie on 2019/10/14.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "SystemMessageController.h"

@interface SystemMessageController ()<UITableViewDelegate,UITableViewDataSource>
/**<#属性#>*/
@property (nonatomic,strong)UITableView*listView;

@end

@implementation SystemMessageController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"系统消息";
    [self.view addSubview:self.listView];
    
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
}
#pragma mark --UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.00f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 12.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return UIView.new;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return UIView.new;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SystemMessageCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SystemMessageCell class])];
    
    return cell;
}
-(UITableView*)listView{
    if(!_listView){
        _listView=[UITableView new];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        [_listView registerClass:[SystemMessageCell class] forCellReuseIdentifier:NSStringFromClass([SystemMessageCell class])];
        _listView.tableFooterView = UIView.new;
        _listView.backgroundColor = UIColorFromRGB(0xF4F5F7);
        
    }
    return _listView;
}
@end


@implementation SystemMessageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)createUI{
    UIImageView * imageView = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"SystemMessage")];
    ViewRadius(imageView, 20);
    
    UILabel * oneLabel = UILabel.new;
    oneLabel.textColor = UIColorFromRGB(0x333333);
    oneLabel.font = PingFangSC_Semibold(15);
    oneLabel.text = @"系统通知";
    
    UILabel * twoLabel = UILabel.new;
    twoLabel.textColor = UIColorFromRGB(0x939699);
    twoLabel.font = PingFangSC_Light(14);
    twoLabel.text = @"系统通知深度对话某某";

    UILabel * thereLabel = UILabel.new;
    thereLabel.textColor = UIColorFromRGB(0x939699);
    thereLabel.font = PingFangSC_Light(14);
    thereLabel.text = @"3天前";

    [self addSubview:imageView];
    [self addSubview:oneLabel];
    [self addSubview:twoLabel];
    [self addSubview:thereLabel];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(18);
        make.width.height.mas_equalTo(40);
    }];
    [oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageView);
        make.left.mas_equalTo(imageView.mas_right).offset(12);
        make.right.mas_equalTo(-20);
    }];
    [twoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(oneLabel);
        make.top.mas_equalTo(oneLabel.mas_bottom).offset(6);
    }];
    [thereLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(oneLabel);
        make.top.mas_equalTo(twoLabel.mas_bottom).offset(6);
        make.bottom.mas_equalTo(-18);
    }];

}
@end
